﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using Microsoft.Surface.Presentation.Manipulations;
using System.Timers;
using System.Windows.Threading;
using MediaSurface.MediaConsumerServiceReference;
using System.Collections;


namespace MediaSurface
{
    /// <summary>
    /// Interaction logic for MediaDetailsUserControl.xaml
    /// </summary>
    public partial class MediaDetailsUserControl : UserControl
    {

        public int movie_id;
        public string movie_title; 
        public string length;
        public string tag; 
        public string pool;
        static LibraryBar mainLbBar1;
        static ScatterView scatterView2;
        int removedValue1;

        
        public MediaDetailsUserControl()
        {
            InitializeComponent();

        }


        public MediaDetailsUserControl(ScatterView scatterV, LibraryBar lb, int removedVal, int id, string title, string length,  string pool, string aspect_ratio, string thumbnail_url, string description)
        {
            InitializeComponent();

           

           ImageSourceConverter imgConv = new ImageSourceConverter();
           string path = thumbnail_url.ToString();
           ImageSource imageSource = (ImageSource) imgConv.ConvertFromString(path);
           movie_thumnnail.Source = imageSource;
            

            scatterView2 = scatterV;

            mainLbBar1 = lb;
            removedValue1 = removedVal;
            movie_id = id;
            movie_title = title;

            title_textBox.Text = title;
            length_textBox.Text = length;
            pool_textBox.Text = pool;
            description_textBox.Text = description;

            
            if (aspect_ratio == "1")
            {
                aspect_ratio_textBox.Text = "4x3";
            }
            if (aspect_ratio == "1")
            {
                aspect_ratio_textBox.Text = "4x3";
            }
            
        }



        private void Close_media_info_Button_Click(object sender, RoutedEventArgs e)
        {
            CloseSurfaceMediaInfoControl((SurfaceButton)sender);

            var item = mainLbBar1.Items[removedValue1];

            mainLbBar1.SetIsItemDataEnabled(item, true);
        }


        private void CloseSurfaceMediaInfoControl(SurfaceButton button) ///Close the mediaDetailsWindow
        {
            DependencyObject parent = LogicalTreeHelper.GetParent(button);
            while (parent != null)
            {
                ScatterViewItem item = parent as ScatterViewItem;
                if (item != null)
                {
                    ScatterView scatterView = LogicalTreeHelper.GetParent(item) as ScatterView;
                    if (scatterView != null)
                    {
                        scatterView.Items.Remove(item);
                        return;
                    }
                }

                parent = LogicalTreeHelper.GetParent(parent);
            }
        }


        private void Play_media_Button_Click(object sender, RoutedEventArgs e)
        {
           /* var newItem1 = new ScatterViewItem { MinWidth = 500, MinHeight = 410 };
           
            int id2 =  movie_id;
            MediaConsumerClient client = new MediaConsumerClient();
            requestMediaStruct result = client.requestMedia(id2, 1);
           
            SurfaceUserControl1 uControl = new SurfaceUserControl1(mainLbBar1, removedValue1, movie_title);
           
            uControl.SetMediaUrl(result.url);
            newItem1.Content = uControl;
            
            

            newItem1.Center = new Point(460,250);
            
            
            scatterView2.Items.Add(newItem1);*/
          
            
            
        }

        
    }
}
